#include "ConfigIni.h"
#include "define.h"
#include <qapplication.h>
#include <qsettings.h>
#include <qfile.h>

ConfigIni::ConfigIni()
{
}

ConfigIni::~ConfigIni()
{
}

void ConfigIni::saveColor(const QColor& color)
{
	QString path = INI_PATH("color.ini");
	QSettings set(path, QSettings::IniFormat);

	set.setValue("COLOR/red",color.red());
	set.setValue("COLOR/green",color.green());
	set.setValue("COLOR/blue",color.blue());
}

QColor ConfigIni::getColor()
{
	QString path = INI_PATH("color.ini");
	if (!QFile::exists(path))
	{
		saveColor(QColor(22,154,218));
	}
	QSettings set(path, QSettings::IniFormat);

	int red = set.value("COLOR/red").toInt();
	int green = set.value("COLOR/green").toInt();
	int blue = set.value("COLOR/blue").toInt();

	return QColor(red,green,blue);
}

void ConfigIni::saveUserProfile(const QString& account, const QString& password)
{
	QString path = INI_PATH("user.ini");
	QSettings set(path, QSettings::IniFormat);

	set.setValue("USER/account",account);
	set.setValue("USER/password", password);
}

bool ConfigIni::getUserProfile(QString& account,QString& password)
{
	QString path = INI_PATH("user.ini");
	if (!QFile::exists(path)) return false;
	QSettings set(path,QSettings::IniFormat);

	account = set.value("User/account").toString();
	password = set.value("User/password").toString();

	return true;
}
